/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action.retail;

import static com.opensymphony.xwork2.Action.SUCCESS;
import com.opensymphony.xwork2.ActionSupport;
import database.ProductDAO;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import model.Category;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

/**
 *
 * @author Thai Ha Cong
 */
public class LinkAction extends ActionSupport {
    
    private Map<Integer, String> allCategories;
    private List<String> allBrands;
    private List<String> allWarranty;
    private List<String> allScreenSize;
    private List<String> allOS;
    private List<String> allStorage;
    private List<String> allCamera;
    
    private ProductDAO productDAO = new ProductDAO();
    
    public LinkAction() {
    }

    public Map<Integer, String> getAllCategories() {
        return allCategories;
    }

    public void setAllCategories(Map<Integer, String> allCategories) {
        this.allCategories = allCategories;
    }

    public List<String> getAllBrands() {
        return allBrands;
    }

    public void setAllBrands(List<String> allBrands) {
        this.allBrands = allBrands;
    }

    public List<String> getAllWarranty() {
        return allWarranty;
    }

    public void setAllWarranty(List<String> allWarranty) {
        this.allWarranty = allWarranty;
    }

    public List<String> getAllScreenSize() {
        return allScreenSize;
    }

    public void setAllScreenSize(List<String> allScreenSize) {
        this.allScreenSize = allScreenSize;
    }

    public List<String> getAllOS() {
        return allOS;
    }

    public void setAllOS(List<String> allOS) {
        this.allOS = allOS;
    }

    public List<String> getAllStorage() {
        return allStorage;
    }

    public void setAllStorage(List<String> allStorage) {
        this.allStorage = allStorage;
    }

    public List<String> getAllCamera() {
        return allCamera;
    }

    public void setAllCamera(List<String> allCamera) {
        this.allCamera = allCamera;
    }

    @Override
    public String execute() throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    @Action(value = "about", results = {
        @Result(name = "success", location = "/about.jsp")
    })
    public String about() {
        return SUCCESS;
    }
    
    @Action(value = "contact", results = {
        @Result(name = "success", location = "/contact.jsp")
    })
    public String contact() {
        return SUCCESS;
    }
    
    @Action(value = "help", results = {
        @Result(name = "success", location = "/help.jsp")
    })
    public String help() {
        return SUCCESS;
    }
    
    @Action(value = "searchForm", results = {
        @Result(name = "success", location = "/advancedSearch.jsp")
    })
    public String search() {
        allCategories = new HashMap<Integer, String>();
//        allCategories.put(0, "All Categories");
        allCategories.put(0, "All");

        for (Category c : productDAO.getAllCategories()) {
            allCategories.put(c.getIdCategory(), c.getName());

            List<Category> childCategories = c.getChildCategories();
            if (childCategories != null) {
                for (Category c2 : childCategories) {
                    allCategories.put(c2.getIdCategory(), "-- " + c2.getName());
                }
            }
        }

        allBrands = new ArrayList<String>();
        allBrands.add("All");

        for (String s : productDAO.getAllBrands()) {
            allBrands.add(s);
        }
        
        allWarranty = new ArrayList<String>();
        allWarranty.add("All");
        allWarranty.add("0 - 12 months");
        allWarranty.add("13 - 36 months");
        allWarranty.add("> 36 months");
        
        allScreenSize = new ArrayList<String>();
        allScreenSize.add("All");
        allScreenSize.add("<= 4.0 inches");
        allScreenSize.add("4.1 - 6.5 inches");
        allScreenSize.add("6.6 - 12.5 inches");
        allScreenSize.add("12.6 - 14.0 inches");
        allScreenSize.add("> 14 inches");
        
        allStorage = new ArrayList<String>();
        allStorage.add("All");
        allStorage.add("<= 16GB");
        allStorage.add("17 - 32GB");
        allStorage.add("33 - 64GB");
        allStorage.add("65 - 256GB");
        allStorage.add("257 - 750GB");
        allStorage.add("> 750GB");
        
        allCamera = new ArrayList<String>();
        allCamera.add("All");
        allCamera.add("<= 3.2MP");
        allCamera.add("3.3 - 8.0MP");
        allCamera.add("8.1 - 16.0MP");
        allCamera.add("> 16.0MP");

        allOS = new ArrayList<String>();
        allOS.add("All");
        allOS.add("Android");
        allOS.add("iOS");
        allOS.add("Windows 7");
        allOS.add("Windows 8");
        
        return SUCCESS;
    }
    
    @Action(value = "paymentPaypal", results = {
        @Result(name = "success", location = "/invalid.jsp")
    })
    public String paymentPaypal() {
        return SUCCESS;
    }
    
    @Action(value = "processOrderForm", results = {
        @Result(name = "success", location = "/processOrder.jsp")
    })
    public String processOrderForm() {
        return SUCCESS;
    }
    
    @Action(value = "Administration", results = {
        @Result(name = "success", location = "/administration/slogin.jsp")
    })
    public String admin() {
        return SUCCESS;
    }
}